//
//  FxWeather.m
//  TodayComment
//
//  Created by 张吉阳 on 15/9/12.
//  Copyright (c) 2015年 xianrenmoshi. All rights reserved.
//

#import "FxWeather.h"
#import "WeatherInfo.h"
@implementation FxWeather
- (void)parseData:(NSData *)data
{
    if (data.length <= 0) { //返回的长度为0，认为成功
        [self parseSuccess:nil jsonString:nil];
        return;
    }
    
    NSString *jsonString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    NSMutableDictionary *dict = [FxJsonUtility jsonValueFromString:jsonString];
    //有漏洞潜在的bug需要解决
    NSString *result = [dict valueForKey:@"success"];
    if ([result isEqualToString:@"1"]) {
    [self parseSuccess:dict jsonString:jsonString];
    }
    else {
    [self parseFail:dict];
    }
    
    _receiveData = nil;
}

- (void)parseSuccess:(NSDictionary *)dict jsonString:(NSString *)jsonString
{

    WeatherInfo *infos = [WeatherInfo infoFromDict:[dict valueForKey:@"result"]];
    [_delegate opSuccess:infos];
}

@end
